/*
 * @Author: chenjie 2466328944@qq.com
 * @Date: 2025-02-07 11:54:42
 * @LastEditors: chenjie 2466328944@qq.com
 * @LastEditTime: 2025-02-07 17:39:20
 * @FilePath: \dictation-service\ruoyi-admin\src\main\java\com\ruoyi\app\controller\HtImportController.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package com.ruoyi.app.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.translate.domain.HtImport;
import com.ruoyi.translate.service.IHtImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 导入Controller
 */
@RestController
@RequestMapping("/system/import")
public class HtImportController extends BaseController {
    @Autowired
    private IHtImportService htImportService;

    /**
     * 查询导入列表
     */
    @PreAuthorize("@ss.hasPermi('system:import:list')")
    @GetMapping("/list")
    public TableDataInfo list(HtImport htImport) {
        startPage();
        List<HtImport> list = htImportService.selectHtImportList(htImport);
        return getDataTable(list);
    }

    /**
     * 导入数据
     */
    @Log(title = "导入管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<HtImport> util = new ExcelUtil<HtImport>(HtImport.class);
        List<HtImport> importList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = htImportService.importData(importList, updateSupport, operName);
        return success(message);
    }

    /**
     * 获取导入详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:import:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(htImportService.selectHtImportById(id));
    }

    /**
     * 修改导入数据
     */
    @PreAuthorize("@ss.hasPermi('system:import:edit')")
    @Log(title = "导入管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HtImport htImport) {
        htImport.setUpdateBy(getUsername());
        return toAjax(htImportService.updateHtImport(htImport));
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws Exception {
        ExcelUtil<HtImport> util = new ExcelUtil<HtImport>(HtImport.class);
        util.importTemplateExcel(response, "导入数据");
    }

    /**
     * 删除导入数据
     */
    @PreAuthorize("@ss.hasPermi('system:import:remove')")
    @Log(title = "导入管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(htImportService.deleteHtImportByIds(ids));
    }
}
